#pragma once
#include <map>	
#include <skyResource\GuiRes.h>
#include <uifactory.h>
#include "xmlForm.h"
using namespace gui;
typedef void (*xml_form_init)(CGraphics &g,xmlForm* pRoot, gui::Control* pctrl, sky_xml::Element* e);

class gameGuiFactory :public gui::UIFactory
{
	SINGLETON(gameGuiFactory);
	gameGuiFactory(void);
	virtual ~gameGuiFactory(void);
public:
	void		InitSkin( const char* configFile , CGraphics &g);
	Skin*		CreateSkin( unsigned int style );
	void		ReleaseSkin( CGraphics &g );
public:
	static void InitControlFromMap(CGraphics &g, xmlForm* pRoot, Control* pctrl, sky_xml::Element* e);
	static void InitControl(CGraphics &g,xmlForm* pRoot,	Control* pctrl, sky_xml::Element* e);
	static void InitButton(CGraphics &g,xmlForm* pRoot,	Button* pctrl, sky_xml::Element* e);
	static void InitStatic(CGraphics &g,xmlForm* pRoot,	Static* pctrl, sky_xml::Element* e);
	static void InitEditBox(CGraphics &g,xmlForm* pRoot,	Editbox* pctrl, sky_xml::Element* e);
	static void InitCheckBox(CGraphics &g,xmlForm* pRoot,	CheckBox* pctrl, sky_xml::Element* e);
	static void InitXmlForm(CGraphics &g,xmlForm* pRoot,	xmlForm* pctrl, sky_xml::Element* e);
	static void InitRadioBox(CGraphics &g,xmlForm* pRoot,	RadioBox* pctrl, sky_xml::Element* e);
	static void InitScrollBar(CGraphics &g,xmlForm* pRoot,	ScrollBar* pctrl, sky_xml::Element* e);
	static void InitTabBox(CGraphics &g,xmlForm* pRoot,	TabBox* pctrl, sky_xml::Element* e);
	static void InitProgressBar(CGraphics &g,xmlForm* pRoot,ProgressBar* pctrl, sky_xml::Element* e);
	static void InitSlider(CGraphics &g,xmlForm* pRoot,	Slider* pctrl, sky_xml::Element* e);
	static void InitListBox(CGraphics &g,xmlForm* pRoot,	ListBox* pctrl, sky_xml::Element* e);
	static void InitComboBox(CGraphics &g,xmlForm* pRoot,	ListBox* pctrl, sky_xml::Element* e);
	static void InitGrid(CGraphics &g,xmlForm* pRoot,	Grid* pctrl, sky_xml::Element* e);
	static int	ReleaseControl(xmlForm* pctrl);
	/*static void InitComboBox(CGraphics &g,ComboBox* pctrl, sky_xml::Element* e);*/
private:
	static HTEXTURE LoadTexture(CGraphics &g,D3DFORMAT fmt, int id, const char* file = 0);
	static void UnLoadTexture(CGraphics &g,int id,HTEXTURE htex);
private:

	static std::map<TYPEID,xml_form_init > CtrlTypeMap;
	struct TextureFile
	{
		std::string filename;
		HTEXTURE tex;
	};
	static std::list<TextureFile> TextureFileMag;

	xmlForm	t_xmlForm;

	std::vector<Skin>	m_skin;
	GUI_Texture			grdTex[4];
	CGraphics			*pGraphics;
};
